package com.zym.controller;

import com.zym.domain.*;
import com.zym.service.IFyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ZouYangMing
 */
@Controller
@RequestMapping("/api")
public class ApiController {

    @Autowired
    IFyService fyService;

    /**
     * 百度翻译API接口
     * @param text 中文字符串
     * @return
     */
    @GetMapping("/Baidu")
    @ResponseBody
    public Object baidu(String text){
        BdFy bdFy = fyService.bdfy(text);
        Map map = new HashMap();
        map.put("cn",bdFy.getDst());
        map.put("en",bdFy.getSrc());
        return AjaxRequest.build(0,"翻译成功",map);
    }

    /**
     * 金山翻译API接口
     * @param text 中文字符串
     * @return
     */
    @GetMapping("/Jinshang")
    @ResponseBody
    public Object Jinshang(String text){
        JsFy jsFy = fyService.jsfy(text);
        Map map = new HashMap();
        map.put("cn",jsFy.getOut());
        map.put("en",jsFy.getText());
        return AjaxRequest.build(0,"翻译成功",map);
    }

    /**
     * 360翻译API接口
     * @param text 中文字符串
     * @return
     */
    @GetMapping("/360")
    @ResponseBody
    public Object Name360(String text){
        Name360Fy name360Fy = fyService.name360fy(text);
        Map map = new HashMap();
        map.put("cn",name360Fy.getFanyi());
        map.put("en",name360Fy.getWord());
        return AjaxRequest.build(0,"翻译成功",map);
    }

    /**
     * 搜狗翻译API接口
     * @param text 中文字符串
     * @return
     */
    @GetMapping("/Sougou")
    @ResponseBody
    public Object Sougou(String text){
        SgFy sgFy = fyService.sgfy(text);
        Map map = new HashMap();
        map.put("cn",sgFy.getV());
        map.put("en",sgFy.getK());
        return AjaxRequest.build(0,"翻译成功",map);
    }

    /**
     * 腾讯翻译API接口
     * @param text 中文字符串
     * @return
     */
    @GetMapping("/Tenxun")
    @ResponseBody
    public Object Tenxun(String text){
        TxFy txFy = fyService.txfy(text);
        Map map = new HashMap();
        map.put("cn",txFy.getTargetText());
        map.put("en",txFy.getSourceText());
        return AjaxRequest.build(0,"翻译成功",map);
    }

    @GetMapping("/Juhe")
    @ResponseBody
    public Object Juhe(String text){
        Map juhe_map = new HashMap();
        BdFy bdFy = fyService.bdfy(text);
        Map bd_map = new HashMap();
        if(bdFy!=null){
            bd_map.put("cn",bdFy.getDst());
            bd_map.put("en",bdFy.getSrc());
        }
        JsFy jsFy = fyService.jsfy(text);
        Map js_map = new HashMap();
        if(jsFy!=null){
            js_map.put("cn",jsFy.getOut());
            js_map.put("en",jsFy.getText());
        }
        Name360Fy name360Fy = fyService.name360fy(text);
        Map n360_map = new HashMap();
        if(name360Fy!=null){
            n360_map.put("cn",name360Fy.getFanyi());
            n360_map.put("en",name360Fy.getWord());
        }
        SgFy sgFy = fyService.sgfy(text);
        Map sg_map = new HashMap();
        if(sgFy!=null){
            sg_map.put("cn",sgFy.getV());
            sg_map.put("en",sgFy.getK());
        }
        TxFy txFy = fyService.txfy(text);
        Map tx_map = new HashMap();
        if(txFy!=null){
            tx_map.put("cn",txFy.getTargetText());
            tx_map.put("en",txFy.getSourceText());
        }
        juhe_map.put("baidu",bd_map);
        juhe_map.put("jingshang",js_map);
        juhe_map.put("360",n360_map);
        juhe_map.put("sougou",sg_map);
        juhe_map.put("tenxun",tx_map);
        return AjaxRequest.build(0,"翻译成功",juhe_map);
    }

}
